//action types
export const actionTypes = {
    ADD_TODO: 'ADD_TODO',
    ADD_TODO_ASYNC: 'ADD_TODO_ASYNC',
    DEL_TODO: 'DEL_TODO',
    TOGGLE_COMPLETE: 'TOGGLE_COMPLETE',
    CHANGE_DISPLAY: 'CHANGE_DISPLAY'
};

//action Creator
const actions = {
    //添加一条待办，payload参数就是一条待办的数据
    addTodo: payload => ({ type: actionTypes.ADD_TODO, payload }),
    //异步更新
    addTodoSync: payload => dispatch => {
        setTimeout(() => {
            dispatch({
                type: actionTypes.ADD_TODO_ASYNC,
                payload
            });
        }, 2000);
    },
    //删除待办项数据，payload为id
    delTodo: payload => ({ type: actionTypes.DEL_TODO, payload }),
    //更改完成状态，此处payload传id
    toggleComplete: payload => ({ type: actionTypes.TOGGLE_COMPLETE, payload }),
    //更改显示待办项的状态，payload为以下3个值（all,uncompleted,completed）
    changeDisplay: payload => ({ type: actionTypes.CHANGE_DISPLAY, payload })
};

export default actions;
